package com.bilibili.bilibili.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bilibili.bilibili.R;
import com.bilibili.bilibili.activity.CommendDetails;
import com.bilibili.bilibili.bean.BangumiXQ;

import java.util.List;

/**
 * 作者： 张贤伟
 * 时间： 2017/3/18 15:20
 * 类描述：番剧详情界面的选集
 */
public class BangumiXQadapter extends RecyclerView.Adapter<BangumiXQadapter.ViewHolder> {
    private Context context;

    public BangumiXQadapter(Context context) {
        this.context = context;
    }

    private List<BangumiXQ.ResultEntity.EpisodesEntity> list;

    public void getdata(List<BangumiXQ.ResultEntity.EpisodesEntity> list) {
        this.list = list;
        this.notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.bangumi_anthology, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {


        holder.index.setText("第" + list.get(position).getIndex() + " 话");
        holder.title.setText(list.get(position).getIndex_title());

        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CommendDetails.class);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView index, title;
        CardView cardView;

        public ViewHolder(View itemView) {
            super(itemView);
            index = (TextView) itemView.findViewById(R.id.tv_index);
            title = (TextView) itemView.findViewById(R.id.tv_title);
            cardView = (CardView) itemView.findViewById(R.id.bang_tvcard);
        }
    }
}
